# -*- coding:utf-8 -*-

import pandas as pd
import os

def csv_to_xlsx_pd(source_path, target_path):
    try:
        data = pd.read_csv(source_path, encoding='utf-8')
        data.to_excel(target_path, sheet_name='data')
        os.remove(source_path)
    except:
        print("=======================")
        print("错误：" + sorurce_path)
        print("=======================")



if __name__ == '__main__':
    list_file = os.listdir("./csv")
    for file in list_file:
        doc_name = file.split(".")[0]
        doc_type = file.split(".")[1]
        if doc_type == "csv":
            sorurce_path = "./csv/" + file
            target_path = "./xls/" + doc_name + ".xlsx"
            print(sorurce_path)
            csv_to_xlsx_pd(sorurce_path, target_path)